
#include "struct.h"
#include "supermarket.h"

//********************************************************************************************************************************
int main() {
	sup a[1000];
	goods g[1000];
	sta s[1000];
	datad r[1000];
	datam t[1000];
	int n = 0;
	int m = 0;
	int p = 0;
	int pm = 0;
	int pd = 0;
	Wellcome(a,n,g,m,s,p,t,pm,r,pd);
	return 0;
}

void Wellcome(sup a[], int n,goods g[], int m,sta s[],int p,datam *t,int pm,datad r[], int pd) {
	char op[20];
	int flag = 1;
	while (flag == 1) {

		system("CLS");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t请选择登录用户\n");
		printf("\t\t1.登录管理用户\n");
		printf("\t\t2.登录普通用户\n");
		printf("\t\t0.退出系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t请选择...\n");

		gets(op);

		if (strcmp(op, "1") == 0) {
			Bossmenu(a,n,g,m,s,p,t,pm,r,pd);
			system("pause");
		} else if (strcmp(op, "2") == 0) {
			Staffmenu(s,p,g,m,t,pm,r,pd);
			system("pause");
		} else if (strcmp(op, "0") == 0) {
			return;
		} else {
			printf("输入有误，请重试");
			system("pause");
		}
	}
}

//管理用户
void Bossmenu(sup a[], int n,goods g[], int m,sta s[],int p,datam *r,int pm,datad t[], int pd) {
	char option1[20];
	int flag = 1;
	while (flag == 1) {
	
		system("CLS");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t1.供应商管理\n");
		printf("\t\t2.商品管理\n");
		printf("\t\t3.员工管理\n");
		printf("\t\t4.采购管理\n");
		printf("\t\t0.退出系统\n");
		printf("\t---------------------------------\n");

		gets(option1);

		if (strcmp(option1, "1") == 0) {
			Supplier_Manage_Menu(a,n);
		} else if (strcmp(option1, "2") == 0) {
			Goods_Manage_Menu(g,m);
		} else if (strcmp(option1, "3") == 0) {
			Staff_Manage_Menu(s,p);
		} else if (strcmp(option1, "4") == 0) {
			Pur_Manage_Menu(r,pm,t,pd);
		} else if (strcmp(option1, "0") == 0) {
			flag = 0;
		}	else {
			printf("输入有误，请重试");
			system("pause");
			return ;
		}
	}
}

int Supplier_Manage_Menu(sup a[], int n) {
	char sup_manage_option[20];
	int flag = 1;

	while (flag == 1) {
		fflush(stdin);
		system("CLS");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t1.批量录入供应商数据\n");
		printf("\t\t2.查询并列出表中所有供应商信息\n");
		printf("\t\t3.修改指定供应商信息\n");
		printf("\t\t4.删除指定供应商数据\n");
		printf("\t\t0.退出\n");
		printf("\t---------------------------------\n");

		gets(sup_manage_option);

		if (strcmp(sup_manage_option, "1") == 0) {
			n = Add_supplier(a,n);

		} else if(strcmp(sup_manage_option, "2") == 0) {
			Search_list_Sup(a, n);
			system("pause");

		} else if (strcmp(sup_manage_option, "3") == 0) {
			Mod_supplier_data(a, n);
			system("pause");
		} else if (strcmp(sup_manage_option, "4") == 0) {
			n = Delete_supplier_data(a,n);
			system("pause");

		} else if (strcmp(sup_manage_option, "0") == 0) {
			flag = 0;
		} else {
			printf("输入有误，请重试");
			system("pause");
		}
	}
}


int Add_supplier(sup a[], int n) {
	printf("请输入要录入的供应商数量:");
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		printf("------------------------------------\n");//????????
		printf("第%d个供应商: \n", i + 1);
		printf("供应商编号:");
		scanf("%d", &a[i].su_num);				//?????
		printf("供应商名称:");
		scanf("%s", a[i].name);					//?????
		printf("简称:");
		scanf("%s", a[i].short_name);			//?????
		printf("地址:");
		scanf("%s", a[i].address);				//??
		printf("公司电话:");
		scanf("%d", &a[i].comp_phoneNum);			//????
		printf("邮件:");
		scanf("%s", a[i].mail);					//??
		printf("联系人:");
		scanf("%s", a[i].contact);				//???
		printf("联系人电话:");
		scanf("%d", &a[i].contactNum);			//?????
		printf("备注:");
		scanf("%s", a[i].su_note);				//??
		printf("------------------------------------\n");
	}
	return n;
}
//2.输出供应商信息

int Search_list_Sup(sup a[], int n) {
	if (n <= 0) {
		printf("前无供应商信息");
	} else {
		for (int i = 0; i < n; i++) {
			printf("供应商编号: %d\n", a[i].su_num);
			printf("供应商名称: %s\n", a[i].name);
			printf("供应商简称: %s\n", a[i].short_name);
			printf("地址: %s\n", a[i].address);
			printf("公司电话: %d\n", a[i].comp_phoneNum);
			printf("邮件: %s\n", a[i].mail);
			printf("联系人: %s\n", a[i].contact);
			printf("联系人电话: %d\n", a[i].contactNum);
			printf("备注: %s\n", a[i].su_note);
			printf("**********\n");
		}
	}
	return n;
}

///3.修改供应商信息
// 修改供应商信息
int Mod_supplier_data(sup a[],int n) {
	int id;
	printf("请输入供应商编号进行修改:");
	scanf("%d", &id);

	for (int i = 0; i < n; i++) {
		if (a[i].su_num == id) {
			printf("供应商编号:" );
			scanf("%d",&a[i].su_num);
			printf("供应商名称:");
			scanf("%s",a[i].name );
			printf("供应商简称:");
			scanf("%s",a[i].short_name);
			printf("地址:");
			scanf("%s", a[i].address);
			printf("公司电话:");
			scanf("%d", &a[i].comp_phoneNum);
			printf("邮件:");
			scanf("%s", a[i].mail);
			printf("联系人:");
			scanf("%s", a[i].contact);
			printf("联系人电话:");
			scanf("%d", &a[i].contactNum);
			printf("备注:");
			scanf("%s", a[i].su_note);
			printf("供应商信息已修改。\n");
		}
	}
	printf("未找到商品编号 %d，请重新输入。\n", id);
}
// 4.删除供应商
int Delete_supplier_data(sup a[],int n) {
	int id;
	printf("请输入要删除的供应商编号:");
	scanf("%d", &id);

	for (int i = 0; i < n; i++) {
		if (a[i].su_num == id) {

			for (int j = i; j < n - 1; j++) {
				a[j] = a[j + 1];
			}
			n--;
			printf("供应商 %d 已被删除。\n", id);
			return n;
		} else	{
			printf("未找到供应商编号 %d，请重新输入\n", id);
		}
	}
}

int Goods_Manage_Menu(goods g[],int m) {

	int flag = 1;
	char goption[20];
	while (flag == 1) {

		fflush(stdin);
		system("cls");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t------------------------------------\n");
		printf("\t\t1.批量录入商品数据\n");
		printf("\t\t2.查询并列出所有商品信息\n");
		printf("\t\t3.修改指定商品信息\n");
		printf("\t\t4.删除指定商品数据\n");
		printf("\t\t0.退出\n");
		printf("\t------------------------------------\n");

		gets(goption);

		if(strcmp(goption,"1") == 0) {
			m = Add_goods_data(g,m);						//2.1批量录入商品数据
		} else if (strcmp(goption,"2") == 0) {
			m = Search_list_goods(g,m);
			system("pause");							//2.2查询并列出所有商品信息
		} else if (strcmp(goption,"3") == 0) {
			m = Mod_goods_data(g,m);
			system("pause");							//修改指定商品信
		} else if (strcmp(goption,"4") == 0) {
			m = Delete_goods_data(g,m);
			system("pause");						//删除指定商品数据
		} else if (strcmp(goption,"0") == 0) {
			return m;
		}
	}
}

int Add_goods_data(goods g[],int m) {											//2.1批量录入商品数据
	printf("请输入要录入的商品数量:");
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		printf("------------------------------------\n");
		printf("第%d个商品: \n", i + 1);
		printf("商品数据:");
		scanf("%s", g[i].data);							//商品数据
		printf("商品编号:");
		scanf("%d", &g[i].Gnum);						//商品编号
		printf("名称:");
		scanf("%s", g[i].Gname);							//名称
		printf("单价:");
		scanf("%d", &g[i].unit_price);					//单价
		printf("供应商编号:");
		scanf("%d", &g[i].Snum);						//供应商编号
		printf("简介:");
		scanf("%s", g[i].brief_intr);					//简介
		printf("备注:");
		scanf("%s", g[i]. Gnote);						//备注
		printf("------------------------------------\n");
	}
	return m;
}


int Search_list_goods(goods g[],int m) {							//2.2查询并列出所有商品信息
	if (m <= 0) {
		printf("当前无商品信息");
		system("pause");
	} else {
		for (int i = 0; i < m; i++) {

			printf("商品编号:%d\n",g[i].Gnum);
			printf("商品数据:%s\n",g[i].data);
			printf("商品名称:%s\n",g[i].Gname);
			printf("商品单价:%d\n",g[i].unit_price);
			printf("供应商编号:%d\n",g[i].Snum);
			printf("简介:%s\n",g[i].brief_intr);
			printf("备注:%s\n",g[i].Gnote);
			printf("**********\n");
		}
	}
	return m;
}

int Mod_goods_data(goods g[],int m) {									//2.3修改指定商品信息
	int id;
	printf("请输入商品编号进行修改:");
	scanf("%d", &id);

	for (int i = 0; i < m; i++) {
		if (g[i].Gnum == id) {
			printf("商品编号:");
			scanf("%d", &g[i].Gnum);
			printf("商品数据:");
			scanf("%s", g[i].data);
			printf("商品名称:");
			scanf("%s", g[i].Gname);
			printf("商品名称:");
			scanf("%d", &g[i].unit_price);
			printf("供应商编号:");
			scanf("%d", &g[i].Snum);
			printf("简介:");
			scanf("%s", g[i].brief_intr);
			printf("备注:");
			scanf("%s", g[i].Gnote);
			printf("商品信息已修改\n");
			return 0;
		}
	}
	printf("未找到供应商编号 %d，请重新输入\n", id);
	return m;
}



int Delete_goods_data(goods g[],int m) {							//2.4删除指定商品数据
	int gid;
	printf("请输入要删除的商品编号:");
	scanf("%d", &gid);

	for (int i = 0; i < m; i++) {
		if (g[i].Gnum == gid) {

			for (int j = i; j < m - 1; j++) {
				g[j] = g[j + 1];
			}
			m--;
			printf("商品%d 已被删除\n", gid);
			return m;
		}
	}
	printf("未找到商品编号 %d，请重新输入\n", gid);
}


int Staff_Manage_Menu(sta s[],int p) {								//3.0员工管理菜单

	int flag = 1;
	char soption[20];

	while(flag == 1) {
		fflush(stdin);
		system("cls");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t1.批量录入员工数据\n");
		printf("\t\t2.查询并列出表中所有员工信息\n");
		printf("\t\t3.修改指定员工信息\n");
		printf("\t\t4.删除指定员工数据\n");
		printf("\t\t0.退出\n");
		printf("\t---------------------------------\n");

		gets(soption);


		if(strcmp(soption,"1") == 0) {
			p = Add_staff_inform(s,p);					//3.1批量录入员工数据
		}	else if(strcmp(soption,"2") == 0) {
			Search_list_staff(s,p);						//3.2列出指定员工信息
		}	else if (strcmp(soption,"3") == 0) {
			p = Mod_staff_data(s,p);						//3.3查询并列出所有员工信息
		}	else if (strcmp(soption,"4") == 0) {
			Delete_staff_data(s,p);						//3.4删除指定员工数据
		}	else {
			return p;
		}
	}
	return p;
}

int Add_staff_inform(sta s[],int p) {				//录入员工信息
	printf("请输入要录入员工的数量:");
	scanf("%d", &p);
	for (int i = 0; i < p; i++) {
		printf("------------------------------------\n");
		printf("第%d个员工: \n", i + 1);
		printf("员工数据:");					//员工数据
		scanf("%s", s[i].stf_data);
		printf("员工编号:");
		scanf("%d", &s[i].stf_num);				//员工编号
		printf("姓名:");
		scanf("%s", s[i].stf_name);						//姓名
		printf("密码:");
		scanf("%s", s[i].password);						//密码
		printf("级别:");
		scanf("%s", &s[i].level);					//级别
		printf("电话:");
		scanf("%d", &s[i].phoneNum);					//电话
		printf("工资:");
		scanf("%d", &s[i].wages);					//工资
		printf("备注:");
		scanf("%s", &s[i].stf_note);					//备注
		printf("------------------------------------\n");
	}
	return p;
}


int Search_list_staff(sta s[],int p) {
	if (p <= 0) {
		printf("当前无员工信息");
		system("pause"); 
	} else {
		for (int i = 0; i < p; i++) {
			printf("员工数据: %s\n", s[i].stf_data);
			printf("员工编号: %d\n", s[i].stf_num);
			printf("姓名: %s\n", s[i].stf_name);
			printf("密码: %s\n", s[i].password);
			printf("级别: %s\n", s[i].level);
			printf("电话: %d\n", s[i].phoneNum);
			printf("工资: %d\n", s[i].wages);
			printf("备注: %s\n", s[i].stf_note);
			printf("**********\n");
			//员工信息
		}
		system("pause");
	}
	return p;
}

int Mod_staff_data(sta s[],int p) {
	int id;
	printf("请输入员工编号进行修改:");
	scanf("%d", &id);

	for (int i = 0; i < p; i++) {
		if (s[i].stf_num == id) {
			printf("员工数据:");
			scanf("%s",s[i].stf_data);
			printf("员工编号：");
			scanf("%d",&s[i].stf_num);
			printf("姓名:");
			scanf("%s",s[i].stf_name);
			printf("密码:");
			scanf("%s", s[i].password);
			printf("级别");
			scanf("%s", s[i].level);
			printf("电话");
			scanf("%d", &s[i].phoneNum);
			printf("工资");
			scanf("%d", &s[i].wages);
			printf("备注:");
			scanf("%s", s[i].stf_note);
			printf("************\n");
			printf("*修改完成");
			system("pause");
		}
	}
	printf("未找到员工编号 %d，请重新输入\n", id);
	return p;
}

int Delete_staff_data(sta s[],int p) {									//删除员工信息
	int sid;
	printf("请输入要删除的员工编号:");
	scanf("%d", &sid);

	for (int i = 0; i < p; i++) {
		if (s[i].stf_num == sid) {							

			for (int j = i; j < p - 1; j++) {
				s[j] = s[j + 1];
			}
			p--;
			printf("员工%d 已被删除\n", sid);
		
		}else {
			printf("未找到员工编号 %d，请重新输入\n", sid);
		
		}
	}return p;	
}

int Pur_Manage_Menu(datam t[],int pm,datad r[], int pd) {								//4.0采购管理(管理用户)
	int flag = 1;
	char puroption[20];

	while (flag == 1) {
		fflush(stdin);
		system("CLS");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t1.录入采购主表数据\n");
		printf("\t\t2.录入采购明细数据\n");
		printf("\t\t3.查询并列出所有采购主表和采购明细信息\n");
		printf("\t\t4.修改指定采购主表信息和采购明细信息\n");
		printf("\t\t5.删除指定采购主表信息和采购明细信息息\n");
		printf("\t\t0.退出\n");
		printf("\t---------------------------------\n");

		gets(puroption);


		if (strcmp(puroption, "1") == 0) {
			pm = Pur_main_list(t,pm);
			system("pause");
		} else if(strcmp(puroption, "2") == 0) {
			pd = Pur_detail_data(r,pd);
			system("pause");
		} else if (strcmp(puroption, "3") == 0) {
			Search_list_pur(t,pm,r,pd);
		} else if (strcmp(puroption, "4") == 0) {
			Mod_pur_data(t,pm,r,pd);
			system("pause");
		} else if (strcmp(puroption, "5") == 0) {
			pm = pd = Delete_pur_data(t,pm,r,pd);
			system("pause");
		} else if (strcmp(puroption, "0") == 0) {
			flag = 0;
		} else {
			printf("输入有误，请重试");
			system("pause");
		}
	}
}

int Pur_main_list(datam t[], int pm) {							//4.1录入采购主表数据
	printf("请输入要录入的采购主表数量:");
	scanf("%d", &pm);
	for (int i = 0; i < pm; i++) {
		printf("------------------------------------\n");
		printf("第%d个: \n", i + 1);
		printf("采购清单号:");
		scanf("%d", &t[i].list_Num);				//采购清单号
		printf("员工编号:");
		scanf("%d", &t[i].snum);					//员工编号
		printf("商品编号:");
		scanf("%d", &t[i].Pur_quantity);			//采购数量
		printf("采购数量:");
		scanf("%d", &t[i].Pur_Total_price);				//采购总价
		printf("商品时间:");
		scanf("%s", t[i].Pur_time);		//采购时间
		printf("备注:");
		scanf("%s", t[i].Pur_note);	//备注

		printf("------------------------------------\n");
	}
	return pm;
}



int Pur_detail_data(datad r[], int pd) {					//4.2录入采购明细数据
	printf("请输入要录入的采购明细表数量:");
	scanf("%d", &pd);
	for (int i = 0; i < pd; i++) {
		printf("------------------------------------\n");
		printf("第%d个: \n", i + 1);
		printf("采购明细号:");					//采购明细号
		scanf("%d", &r[i].pur_dtil_num);
		printf("采购清单号:");					//采购清单号
		scanf("%d", &r[i]. list_Num);
		printf("商品编号:");					//商品编号
		scanf("%d", &r[i].Gnum);
		printf("采购数量:");					//采购数量
		scanf("%d", &r[i].Pur_quantity);
		printf("商品单价:");					//商品单价
		scanf("%d", &r[i].Pur_unit_price);
		printf("商品总价:");							//商品总价
		scanf("%d", &r[i].Total_price_goods);
		printf("备注:");							//备注
		scanf("%s",r[i].pur_dtil_note);
		printf("------------------------------------\n");
	}
	return pd;
}


int Search_list_pur(datam t[],int pm,datad r[], int pd) {					//4.3查询并列出所有采购主表和采购明细信息
	char option_pur[20];
	int flag = 1;
	while (flag == 1) {

		gets(option_pur);
		fflush(stdin);
		system("CLS");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t1.查询主表数据\n");
		printf("\t\t2.查询明细数据\n");
		printf("\t\t0.退出\n");
		printf("\t---------------------------------\n");
		printf("请输入...");

		if(strcmp(option_pur,"1") == 0) {
			if (pm <= 0) {
				printf("暂无主表信息");
				system("pause");
			} else {
				for (int i = 0; i < pm; i++) {
					printf("采购清单号: %d\n", t[i].list_Num);
					printf("员工编号: %d\n", t[i].snum);
					printf("采购数量: %d\n", t[i].Pur_quantity);
					printf("采购总价: %d\n", t[i].Pur_Total_price);
					printf("采购时间: %s\n", t[i].Pur_time);
					printf("备注: %s\n", t[i].Pur_note);
					printf("**********\n");
				}
				system("pause");
			}
			return pm;
		} else if(strcmp(option_pur,"2") == 0) {
			if (pd <= 0) {
				printf("暂无明细表信息");
				system("pause");
			} else {
				for (int i = 0; i < pd; i++) {
					printf("采购明细号: %d\n", r[i].pur_dtil_num);
					printf("采购清单号: %d\n", r[i].list_Num);
					printf("商品编号: %d\n", r[i].Gnum);
					printf("采购数量: %d\n", r[i].Pur_quantity);
					printf("商品单价: %d\n", r[i].Pur_unit_price);
					printf("商品总价: %d\n", r[i].Total_price_goods);
					printf("备注: %s\n", r[i].pur_dtil_note);
					printf("**********\n");
				}
				system("pause");
			}
			return pd;
		}	else if(strcmp(option_pur,"0") == 0) {
			flag = 0;
		}
	}
}

int Mod_pur_data(datam t[],int pm,datad r[], int pd) {					//修改指定采购主表信息和采购明细信息
	char option_Mod[20];
	int flag = 1;
	while (flag == 1) {

		gets(option_Mod);
		fflush(stdin);
		system("CLS");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t1.修改主表数据\n");
		printf("\t\t2.修改明细数据\n");
		printf("\t\t0.退出\n");
		printf("\t---------------------------------\n");

		if(strcmp(option_Mod,"1") == 0) {

			int id;
			printf("请输入采购清单号进行修改:");
			scanf("%d", &id);

			for (int i = 0; i < pm; i++) {
				if (t[i].list_Num == id) {
					printf("采购清单号:");								//采购清单号
					scanf("%d",&t[i].list_Num);
					printf("员工编号:");									//员工编号
					scanf("%d", &t[i].snum);
					printf("采购数量");								//采购数量
					scanf("%d",&t[i].Pur_quantity);
					printf("采购总价");								//采购总价
					scanf("%s",&t[i].Pur_Total_price);
					printf("采购时间:");								//采购时间
					scanf("%s", t[i].Pur_time);
					printf("备注:");									//备注
					scanf("%s", t[i].Pur_note);

					printf("采购主表信息已修改\n");
					return 0;
				}
			}
			printf("未找到采购清单号 %d，请重新输入\n", id);
			return pm;

		}	else if(strcmp(option_Mod,"2") == 0) {
			int id2;
			printf("请输入采购清单号进行修改:");
			scanf("%d", &id2);

			for (int i = 0; i < pd; i++) {
				if (r[i].pur_dtil_num == id2) {
					printf("采购明细号:");								//采购明细号
					scanf("%d",&r[i].pur_dtil_num);
					printf("采购清单号:");								//采购清单号
					scanf("%d",&r[i].list_Num);
					printf("商品编号:");									//商品编号
					scanf("%d",&r[i].Gnum);
					printf("采购数量:");								//采购数量
					scanf("%d",&r[i].Pur_quantity);
					printf("商品单价:");								//商品单价
					scanf("%s",&r[i].Pur_unit_price);
					printf("商品总价:");								//商品总价
					scanf("%s", r[i].Total_price_goods);
					printf("备注:");									//备注
					scanf("%s", r[i].pur_dtil_note);

					printf("采购明细信息已修改\n");
					
				}
			}
			printf("未找到采购明细号 %d，请重新输入\n", id2);
			return pd;
		}
	}
}

int Delete_pur_data(datam t[],int pm,datad r[], int pd) {

	char option_del[20];
	int flag = 1;
	while (flag == 1) {

		gets(option_del);
		fflush(stdin);
		system("CLS");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t1.修改采购主表数据\n");
		printf("\t\t2.修改采购明细数据\n");
		printf("\t\t0.退出\n");
		printf("\t---------------------------------\n");

		if(strcmp(option_del,"1") == 0) {
			int id;
			printf("请输入要删除的采购清单号:");
			scanf("%d", &id);
			int i;
			int j;

			for ( i = 0; i < pm; i++) {
				if (t[i].list_Num == id) {
					for (j = i; j < pm - 1; j++) {
						t[j] = t[j + 1];
					}
					pm--;
					printf("采购清单号 %d 已被删除\n", id);
					return pm;
				} else {
					printf("未找到采购清单号 %d，请重新输入\n", id);
				}
			}
			return pd;
		} else if (strcmp(option_del,"2") == 0) {
			int id;
			printf("????????????:");
			scanf("%d", &id);
			for (int i = 0; i < pd; i++) {
				if (r[i].pur_dtil_num == id) {
					for (int j = i; j < pd - 1; j++) {
						r[j] = r[j + 1];
					}
					pd--;
					printf("请输入要删除的采购清单号\n", id);
					return pd;
				} else {
					printf("未找到采购清单号 %d，请重新输入\n", id);
				}
			}
			return pd;
		}
	}
}
//*******************************************************************

//普通用户登录界面
int Staffmenu(sta s[],int p,goods g[],int m,datam t[],int pm,datad r[], int pd) {
	char staffoption[20];
	int flag = 1;
	while (flag == 1) {

		system("CLS");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t1.查询自己员工信息\n");
		printf("\t\t2.查询所有商品信息\n");
		printf("\t\t3.查询所有采购信息\n");
		printf("\t\t0.退出系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t请选择...\n");

		gets(staffoption);

		if (strcmp(staffoption, "1") == 0) {
			p = Search_staff(s,p);
			system("pause");
		} else if (strcmp(staffoption, "2") == 0) {
			Search_goods(g,m);
			system("pause");
		} else if (strcmp(staffoption, "3") == 0) {
			Search_pur(t,pm,r,pd);
			system("pause");
		} else if (strcmp(staffoption, "0") == 0) {
			flag = 0;
		} else {
			printf("输入有误，请重试");
			system("pause");
		}
		return 0;
	}

}

int Search_staff(sta s[],int p) {				//查询自己员工信息
	int myid;
	printf("请输入您的员工编号：");
	scanf("%d",&myid); 

	for (int i = 0; i < p; i++) {
		if (strcmp("s[i].stf_num", "myid") == 0) {
			printf("员工数据: %s\n", s[i].stf_data);
			printf("员工编号: %d\n", s[i].stf_num);
			printf("姓名: %s\n", s[i].stf_name);
			printf("密码: %s\n", s[i].password);
			printf("级别: %s\n", s[i].level);
			printf("电话: %d\n", s[i].phoneNum);
			printf("工资: %d\n", s[i].wages);
			printf("备注: %s\n", s[i].stf_note);
			printf("**********\n");
		}else {
		}
	}
}



int Search_goods(goods g[],int m) {						//查询所有商品信息
	if (m <= 0) {
		printf("无当前商品信息");
		system("pause");
	} else {
		for (int i = 0; i < m; i++) {

			printf("商品编号:%d\n",g[i].Gnum);
			printf("商品数据:%d\n",g[i].data);
			printf("商品名称:%s\n",g[i].Gname);
			printf("商品单价:%d\n",g[i].unit_price);
			printf("供应商编号:%d\n",g[i].Snum);
			printf("简介:%s\n",g[i].brief_intr);
			printf("备注:%s\n",g[i].Gnote);
			printf("**********\n");
		}
	}
	return m;
}


int Search_pur(datam t[],int pm,datad r[], int pd) {	//查询所有采购信息
	char option_pur[20];
	int flag = 1;
	while (flag == 1) {

		gets(option_pur);
		fflush(stdin);
		system("CLS");
		printf("\n");
		printf("\t\t超市进销管理系统\n");
		printf("\t---------------------------------\n");
		printf("\t\t1.查询并列出主表数据\n");
		printf("\t\t2.查询并列出明细数据\n");
		printf("\t\t0.退出\n");
		printf("\t---------------------------------\n");
		printf("请输入...");

		if(strcmp(option_pur,"1") == 0) {
			if (pm <= 0) {
				printf("暂无主表信息");
				system("pause");
			} else {
				for (int i = 0; i < pm; i++) {
					printf("采购清单号: %d\n", &t[i].list_Num);
					printf("员工编号: %d\n", &t[i].snum);
					printf("采购数量: %d\n", &t[i].Pur_quantity);
					printf("采购总价: %d\n", &t[i].Pur_Total_price);
					printf("采购时间: %s\n", t[i].Pur_time);
					printf("备注: %s\n", t[i].Pur_note);
					printf("**********\n");
				}
				system("pause");
			}
			return pm;
		} else if(strcmp(option_pur,"2") == 0) {
			if (pd <= 0) {
				printf("暂无明细表信息");
				system("pause");
			} else {
				for (int i = 0; i < pd; i++) {
					printf("采购明细号: %d\n", &r[i].pur_dtil_num);
					printf("采购清单号: %d\n", r[i].list_Num);
					printf("商品编号: %d\n", r[i].Gnum);
					printf("采购数量: %d\n", r[i].Pur_quantity);
					printf("商品单价: %d\n", r[i].Pur_unit_price);
					printf("商品总价: %d\n", r[i].Total_price_goods);
					printf("备注: %s\n", r[i].pur_dtil_note);
					printf("**********\n");
				}
				system("pause");
			}
			return pd;
		}
	}
}